package com.atzxh.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author 小红同学
 * @create 2022-10-11-10:32
 * @description
 */
public class Collection_Iterator {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        Collection col = new ArrayList();


        col.add(new Book("三国","罗",88));
        col.add(new Book("水浒","施耐庵",88));
        col.add(new Book("红楼梦","曹雪芹",88));

        //遍历集合
        //1. 先得到col 对应的迭代器
        Iterator iterator = col.iterator();
        //2. while遍历
//        while (iterator.hasNext()){
//            Object next = iterator.next();
//            System.out.println(next);
//        }

        //3. 使用快捷键自动生成 iterator遍历    -->  itit
        //   显示所有快捷键的快捷键   ctrl + J
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
        StringBuffer buffer = new StringBuffer();
        String s = buffer.toString();

        //4. 如果需要再次遍历，需要重置迭代器
        iterator = col.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }

    }
}


